package com.loja.filtro;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import com.loja.dao.GenericDAO;
import com.loja.instrumento.model.Instrumento;
import com.loja.util.HibernateUtil;




@WebFilter(urlPatterns={"/guitarra"}) 
public class ConectionFilter implements Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		GenericDAO<Instrumento> dao=new GenericDAO<Instrumento>(HibernateUtil.openSession());
		
		request.setAttribute("dao", dao);
		System.out.println("filtro do banco");
		chain.doFilter(request, response);
		
		dao.commit();
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
